package com.qianyu.project.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.ContractReceipt;
import com.qianyu.project.mapper.ContractReceiptMapper;
import com.qianyu.project.service.IContractReceiptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianyu.project.utils.PageUtil;
import com.qianyu.project.vo.ContractReceiptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 * 合同收款 服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-01-30
 */
@Service
public class ContractReceiptServiceImpl extends ServiceImpl<ContractReceiptMapper, ContractReceipt> implements IContractReceiptService {

    @Autowired
    private ContractReceiptMapper contractReceiptMapper;

    @Override
    public String getMaxId() {
        String id = contractReceiptMapper.getMaxId();
        if (id == null){
            id = DateUtil.today().replaceAll("-", "") + "000";
        }
        return id;
    }
    @Transactional
    @FlowBegin("contract_receipt")
    @Override
    public Integer saveDetail(@FlowEntry("id") ContractReceipt contractReceipt) {
        contractReceipt.setApproveStatus(1);
        contractReceiptMapper.insert(contractReceipt);
        return 1;
    }

    @Override
    public IPage<ContractReceiptVo> getList(Map<String, String> params) {
        return contractReceiptMapper.getList(PageUtil.createPage(params), params);
    }

    @Override
    public ContractReceiptVo selectOne(String id) {
        return contractReceiptMapper.getOne(id);
    }
}
